package com.wisdytech.common.websocket.service;

import com.wisdytech.common.websocket.handler.WebSocketPushHandler;
import com.wisdytech.linkdcs.configuration.dto.ConfigurationEqDto;
import com.wisdytech.linkdcs.configuration.service.ITtEqConfigurationDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

/**
 * 组态定时推送任务
 * @author dlb
 *
 */
@Component
public class ConfigurationQuartzService {


	@Autowired
	private ITtEqConfigurationDataService configurationDataService;
	


	/**
	 * 定时推送websocket设备参数实时数据
	 * 每分钟推送一次
	 */
	@Scheduled(cron="${websocket.scheduled-cron}")
	public void sendEqParamValue() {
		//获取缓存的session
		Set<Entry<String, WebSocketSession>> entrys =
				WebSocketPushHandler.userSessionLists.entrySet();
		
		for(Entry<String, WebSocketSession> entry : entrys) {
			
			WebSocketSession session =entry.getValue();
			String configurationId =(String) session.getAttributes().get("zutaiId");
			
			List<ConfigurationEqDto>  eqDtos=
					configurationDataService.getEquipmentRealData(configurationId);
			configurationDataService.pushEquipmentData(eqDtos, session);
			
		}
		
	}
	

	
}
